//
//  UIBarButtonItem+Extension.swift
//  XinLangMicroblog
//
//  Created by MackBook on 16/9/23.
//  Copyright © 2016年 zx540006260. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    //在分类中不能使用指定的构造器.init.需要+便利构造器
    
    convenience init(title :String = "",imageName:String,target: Any?, action: Selector) {
        
        let button = UIButton()
        
        button.setTitle(title, for: .normal)
        
        button.setTitleColor(UIColor.gray, for: .normal)
        
        button.setTitleColor(UIColor.orange, for: .highlighted)
        
        button.titleLabel?.font = UIFont.systemFont(ofSize: 18)
        
        button.setImage(UIImage(named: imageName), for: .normal)
        
        button.setImage(UIImage(named: imageName+"_highlighted"), for: .highlighted)
        
        button.sizeToFit()
        
        button.addTarget(target, action:action, for: .touchUpInside)
        
        self.init ()
        
        self.customView = button
        
    }
    
    
    
    
    
    
    
    
    
}
